package com.dyz.LeetCodeforSwordFingerOffer;

import java.util.ArrayList;

/**
 * @author: daiyizheng
 * @date: 2021/7/3 19:59
 * @description:
 */
public class LastRemaining65 {
    public static void main(String[] args) {
        new LastRemaining65().lastRemaining(5,3);
    }
    public int lastRemaining(int n, int m) {
        ArrayList<Integer> list = new ArrayList<>();
        for (int i=0; i<n;i++){
            list.add(i);
        }
        int res = -1;
        int pre = 0;
        while (list.size()>0){
            int cur = (pre+m-1) %list.size();
            res = list.remove(cur);
            pre = cur;
            System.out.println(res);
        }
        return res;
    }
}
